package com.gan.springbootdemo.application;

import com.gan.springbootdemo.util.Constant;
import com.gan.springbootdemo.util.SessionRedis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("usr")
public class UsrController {
    /**
     * request
     */
    @Autowired
    private HttpServletRequest request;
    /**
     * redisTemplate
     */
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @GetMapping("/redis")
    @ResponseBody
    public Map redis() {
        String usrString = SessionRedis.getUsr(request, redisTemplate);
        Map map = new HashMap();
        map.put("usr", usrString);
        return map;
    }
}
